<%@ page language="java" contentType="text/html; charset=UTF-8" isELIgnored="false" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <meta charset="UTF-8">
    <title>随访组信息</title>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/common/layui/css/layui.css"
          media="all">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/common/bootstrap/css/bootstrap.css"
          media="all">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/common/global.css">
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/common/bootstrap/js/jquery-1.12.4.js"></script>
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/common/bootstrap/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/jsplug/echarts.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/common/layui/layui.js"></script>
    <%--日期控件--%>
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/common/My97DatePicker/WdatePicker.js"></script>
</head>
<body>
<div class="container">
        <div class="panel-heading">
            <h1>
                <small style="color: blue;"><b>随访管理组：</b></small>
                <a href="/group/select" style="color: orange; font-size: 17px"><b>新建随访组</b></a>
            </h1>
        </div>
        <div class="panel-body">
            <form action="" id="formGrouptable" method="post" class="form-horizontal">
            <div class="col-sm-12">
                <div class="form-group col-sm-1">
                    <label for="principal" class="control-label">负责人:
                    </label>
                </div>
                <div class=" col-sm-2">
                    <input type="text" class="form-control" id="principal" name="principal" value="${grouptable.principal}">
                </div>
                <div class="form-group col-sm-1">
                    <label for="departmentId" class="control-label">科室</label>
                </div>
                <div class=" col-sm-2">
                    <select class="form-control" name="departmentId" id="departmentId" autocomplete="off" >
                        <option value="">请选择</option>
                        <c:forEach var="departmentlist" items="${departmentList}">
                            <c:if test="${grouptable.departmentId == departmentlist.departmentId}">
                                <option value="${departmentlist.departmentId}" selected>${departmentlist.departmentName}</option>
                            </c:if>
                            <c:if test="${grouptable.departmentId != departmentlist.departmentId}">
                                <option value="${departmentlist.departmentId}">${departmentlist.departmentName}</option>
                            </c:if>
                        </c:forEach>
                    </select>
                </div>
                <div class="form-group col-sm-1">
                    <label for="state" class="control-label">状态</label>
                </div>
                <div class="form-group col-sm-2">
                    <select class="form-control" name="state" id="state" autocomplete="off">
                        <option value="">请选择</option>
                        <c:if test="${grouptable.state !=null}">
                            <c:if test="${grouptable.state ==1}">
                                <option value="${grouptable.state}" selected>开放</option>
                                <option value="2">关闭</option>
                            </c:if>
                            <c:if test="${grouptable.state ==2}">
                                <option value="1">开发</option>
                                <option value="${grouptable.state}" selected>关闭</option>
                            </c:if>
                        </c:if>
                        <c:if test="${grouptable.state == null}">
                            <option value="1">开放</option>
                            <option value="2">关闭</option>
                        </c:if>
                    </select>
                </div>
            </div>
            <div class="col-sm-12">
                <div class="form-group col-sm-1">
                    <label for="beginTimes" id="kai" class="control-label">创建日期:
                    </label>
                </div>
                <div class="col-sm-2">
                    <input onclick="WdatePicker({maxDate:'#F{$dp.$D(\'endTimes\')}'});" class="form-control" id="beginTimes" name="beginTimes" value="${grouptable.beginTimes}">
                </div>
                <div class="form-group col-sm-1">
                    <label  class="control-label" id="jie">——</label>
                </div>
                <div class="col-sm-2">
                    <input onclick="WdatePicker({minDate:'#F{$dp.$D(\'beginTimes\')}'});" class="form-control" id="endTimes" name="endTimes" value="${grouptable.endTimes}">
                </div>
                <div class="form-group col-sm-1"></div>
                <div class="form-group col-sm-1 ">
                    <button id="selectGrouptable" type="button"  class="btn btn-primary btn-block">检索</button>
                </div>
                <div class="form-group col-sm-1"></div>
                <div class="form-group col-sm-1 ">
                    <button id="qingkong" type="button"  class="btn btn-primary btn-block">清空</button>
                </div>
            </div>
            </form>
            <div class="col-sm-12">
                <div class=" col-sm-1">
                    <button type="button" id="bianji" class="btn btn-primary btn-block">编辑</button>
                </div>
                <div class="form-group col-sm-1"></div>
                <div class="form-group col-sm-1">
                    <button type="button" id="delete" class="btn btn-primary btn-block">删除</button>
                </div>
                <div class=" col-sm-1">
                    <button style="display: none" type="button" id="baocun" class="btn btn-primary btn-block">保存</button>
                </div>
                <div class="form-group col-sm-1"></div>
                <div class="form-group col-sm-1">
                    <button style="display: none" type="button" id="fanhui" class="btn btn-primary btn-block">返回</button>
                </div>
            </div>
            <div class="col-sm-12">
                <div class="form-group col-sm-12">
                    <table class="table table-bordered">
                        <thead>
                        <tr>
                            <th></th>
                            <th>名称</th>
                            <th>负责人</th>
                            <th>状态</th>
                            <th>科室</th>
                            <th>创建日期</th>
                        </tr>
                        </thead>
                        <tbody>

                        <c:forEach var="grouptablelist" items="${grouptableList.list}">
                            <tr>
                                <td>
                                    <div class="checkbox">
                                        <label><input type="checkbox" name="groupId" value="${grouptablelist.groupId}"></label>
                                    </div>
                                </td>
                                <td>
                                    <a href='${pageContext.request.contextPath}/foGroup/list?foGroupId=${grouptablelist.groupId}'>
                                        ${grouptablelist.gname}</a></td>
                                <td>${grouptablelist.principal}</td>
                                <td>
                                    <c:if test="${grouptablelist.state==1}">开发</c:if>
                                    <c:if test="${grouptablelist.state==2}">关闭</c:if>
                                </td>
                                <td>${grouptablelist.departments.departmentName}</td>
                                <td><fmt:formatDate pattern="yyyy-MM-dd" value="${grouptablelist.creatorTime}"/></td>
                            </tr>
                        </c:forEach>
                        </tbody>
                    </table>
                </div>
            </div>
            <div class="col-sm-12">
                跳转到<input type="text" id="tiaozhuan"/><button id="go">GO</button></label>
            </div>
        </div>
</div>
</body>
<script type="text/javascript">
    $(function () {
        //跳转至
        $("#go").click(function () {
            var tiao=$("#tiaozhuan").val();
            $("#formGrouptable").attr("action","list?currentPage="+tiao);
            $("#formGrouptable").submit();
        });
        //检索
        $("#selectGrouptable").click(function () {
                $("#formGrouptable").attr("action","list");
                $("#formGrouptable").submit();

        });
        //清空
        $("#qingkong").click(function () {
            $("#kai").html("创建日期");
            $("#jie").html("——");
            $("#beginTimes").val("");
            $("#endTimes").val("");
            $("#principal").val("");
            $("#state").find("option:first").prop("selected",true);
            $("#departmentId").find("option:first").prop("selected",true);
        });
        //全选
        function checkAll(){
            var checkedOfAll=$("#listCheckbox").prop("checked");
            $("input[name='groupId']").prop("checked", checkedOfAll);
        }
        //批量删除
        $("#delete").click(function () {
                var id_array = [];
                $("input[name='groupId']:checked").each(function (i) {
                    id_array.push($(this).val())
                });
                $.ajax({
                    url:"../../group/delete",
                    type:"POST",
                    data: "groupId=" + id_array,
                    dataType:"JSON",
                    success:function(data){
                        if(data>0){
                            location.href="${pageContext.request.contextPath}/group/list";
                        }
                    }
                });
        });
        //编辑
        var an="";
        var bn="";
        $("#bianji").click(function () {
            var id_array =$("input[name='groupId']:checked");
            if(id_array.length==1){
                $.ajax({
                    url:"${pageContext.request.contextPath}/group/selectOne",
                    type:"POST",
                    data:{"groupId":id_array[0].value},
                    dataType:"JSON",
                    success:function(data){
                        if(data!=null){
                            $("#kai").html("开始日期");
                            $("#jie").html("结束日期");
                            $("#principal").val(data.principal);
                            $("#departmentId option[value='"+data.departmentId+"']").attr("selected",true);
                            an=data.departmentId;
                            $("#state option[value='"+data.state+"']").attr("selected",true);
                            bn=data.state;
                            $("#beginTimes").attr("value",data.beginTimes);
                            $("#endTimes").attr("value",data.endTimes);
                            $("#bianji").attr("style","display: none");
                            $("#delete").attr("style","display: none");
                            $("#baocun").attr("style","display: block");
                            $("#fanhui").attr("style","display: block");
                        }
                    }
                });
            }else{
                alert("请选择一条数据进行编辑！");
            }
        });

        $("#fanhui").click(function () {
            $("#kai").html("创建日期");
            $("#jie").html("——");
            $("#beginTimes").attr("value","");
            $("#endTimes").attr("value","");
            $("#principal").val("");
            $("#departmentId option[value='"+an+"']").attr("selected",false);
            $("#state option[value='"+bn+"']").attr("selected",false);
            $("#bianji").attr("style","display: block");
            $("#delete").attr("style","display: block");
            $("#baocun").attr("style","display: none");
            $("#fanhui").attr("style","display: none");
        });
        //修改
        $("#baocun").click(function () {
            if(index3&&index4){
                var id_array =$("input[name='groupId']:checked");
                if(id_array.length==1){
                    var groupId=id_array[0].value;
                    var data = $.param({groupId: groupId}) + "&" + $("#formGrouptable").serialize() + "";
                    $.ajax({
                        url:"${pageContext.request.contextPath}/group/update",
                        type:"post",
                        data:data,
                        dataType:"JSON",
                        success:function(result){
                            if(result==1){
                                location.href = "${pageContext.request.contextPath}/group/list";
                            }
                        }
                    });
                }
            }else {
                alert("请填写正确的修改数据！")
            }
        })
    })
</script>
</html>